﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MaxLeaf.Platform.Contract;
using MaxLeaf.Platform.DataContract;
using CommonsLib.DB;
using System.Transactions;
using System.Data.SqlClient;
using System.Data.Common;
using System.Diagnostics;
using CommonsLib.Settings;
using System.Data;

using System.Security.Cryptography;
using MaxLeaf.Platform.Functions;
using MaxLeaf.Platform.Commons;
using CommonsLib.Utility;

namespace MaxLeaf.Platform.DALImplementation
{
    public class SCPCategoryDAL : BaseDAL 
    {


        public DbDataReader GetSCPCategory(DBAccess dbcon, int intUserID, int intGoodsID, bool blnTop)
        {
            string strSql = string.Empty;

            int intCompanyID = CvtFunc.ToInt(DataFunc.GetFieldValue(dbcon, "muser_main", "CompanyID", new Dictionary<string, object>() { { "userid", intUserID } }));
            strSql=string.Format(@"select  c.* from SCPCategory c where c.FinterID=dbo.F_GetSCPCategoryID(@CompanyID,@GoodsID,{0})
            "
                , (blnTop ? 1 : 0)
                    );

            return dbcon.GetDataReader(strSql, new SqlParameter[]
                        {
                            new SqlParameter("@CompanyID",intCompanyID.ToString())
                            ,new SqlParameter("@GoodsID",intGoodsID.ToString())
                    
                        }
                      );
        }

        public int GetNextSCPCategorySeqNo(DBAccess dbcon, SCPCategoryDataModel scp)
        {
            return CvtFunc.ToInt(dbcon.GetValue("select max(SCPCategorySeqNo) from SCPCategory  where CompanyID=@CompanyID", new SqlParameter[] { new SqlParameter("@CompanyID", scp.CompanyID) })) + 1;
        }
    }
}
